import Taro,{ Component } from '@tarojs/taro'
import { View , Image , Text} from '@tarojs/components'

import './newsItem.scss'


export default class newsItem extends Component {
  static options = {
    addGlobalClass: true
  }

  defaultProps = {
    newsData : {},
  }

  onItemClick = (data) => {
    if (data && data.id){
      Taro.navigateTo({
        url:`/pages/index/newsDetail?newsId=` + data.id
      })
    }
  }

  render(){
    let newsData = this.props.newsData;

    let infoStyle = newsData.newsCover ? 'news-item-info' : 'news-item-info-all'

    return(
      <View className='news-item-container' onClick={this.onItemClick.bind(this , newsData)}>
        <View className='news-item-main'>
          {
            newsData.newsCover &&
            <Image className='news-item-image' src={newsData.newsCover} mode='aspectFit' />
          }
          <View className={infoStyle}>
            <Text className='news-item-title'>{newsData.title}</Text>
            <Text className='news-item-time'>{newsData.releaseDate}</Text>
          </View>
        </View>
        <View className='news-item-divider' />
      </View>
    )
  }
}
